﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SX.BaseService.API.Base;
using SX.BaseService.Service;
using SX.BaseService.Service.ViewModel;
using SX.Core;


namespace SXFramWork.API.Controllers.Admin
{
   
    [Menu]
    [Description("字典管理")]
    public class SysDictionaryController : BaseController
    {
        private readonly ISysDictionaryService _dicService;
        public SysDictionaryController(ISysDictionaryService sysDictionaryService)
        {
            _dicService = sysDictionaryService;
        }

       
        [Description("通用字典")]
        [HttpGet]
        public async Task<IApiResult> Query([FromQuery] string name)
        {
            return await _dicService.Query(name);
        }

        [HttpGet]
        [AllowAnonymous]
        [Description("查询所有的头结点")]
        public async Task<IApiResult> QueryParents()
        {
            return await _dicService.QueryParents();
        }
       
        [HttpPost]
        [Description("新增")]
        public async Task<IApiResult> Add([FromBody] DictionaryAddModel model)
        {
            return await _dicService.Add(model);
        }
        
        [HttpPost]
        [Description("删除")]
        public async Task<IApiResult> Delete([FromBody]List<string> ids)
        {
            return await _dicService.Delete(ids);
        }
       
        [HttpGet]
        [Description("详情")]
        public async Task<IApiResult> Get([FromQuery] string id)
        {
            return await _dicService.GetById(id);
        }
        
        [HttpPost]
        [Description("更新")]
        public async Task<IApiResult> Update([FromBody] DictionaryUpdateModel model)
        {
            return await _dicService.Update(model);
        }

    }
}